package oj;

public class Day15S {
    /**
     * 运用贪心算法的思想：先让局部最优，在让整体最优
     * @param n
     * @param left
     * @param right
     * @return
     */
    public int findMinimum(int n, int[] left, int[] right) {
        // write code here
        int leftSum=0,rightSum=0;
        int leftMin=Integer.MAX_VALUE;
        int rightMin=Integer.MAX_VALUE;
        int sum=0;
        for (int i = 0; i <n; i++) {
            if(left[i]*right[i]==0){
                sum+=left[i]+right[i];
            }else {
                leftSum+=left[i];
                rightSum+=right[i];
                leftMin=Math.min(left[i],leftMin);
                rightMin=Math.min(right[i],rightMin);
            }
        }
        return sum+Math.min(leftSum-leftMin,rightSum-rightMin)+1;
    }
}
